package cn.com.thinvent.dispatch.web.controller;

import cn.com.thinvent.dispatch.entity.DataCleanTask;
import cn.com.thinvent.dispatch.entity.dto.DataCleanTaskDTO;
import cn.com.thinvent.dispatch.entity.response.PagedGridResult;
import cn.com.thinvent.dispatch.entity.response.ReturnModel;
import cn.com.thinvent.dispatch.service.biz.DataCleanTaskService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 清洗任务模块管理
 */
@Api(description = "清洗任务模块")
@Controller
@RequestMapping("/dataCleanTask")
@CrossOrigin(origins = "*")
@ResponseBody
public class DataCleanTaskController {

    @Autowired
    private DataCleanTaskService dataCleanTaskService;

    /**
     * 分页查询任务列表
     * @param taskName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public ReturnModel list(@RequestParam(value = "taskName", required = false) String taskName,
                            @RequestParam("pageNum") Integer pageNum,
                            @RequestParam("pageSize") Integer pageSize) {
        PagedGridResult<DataCleanTask> list = dataCleanTaskService.list(taskName, pageNum, pageSize);
        return new ReturnModel(200, list, "");
    }

    /**
     * 新增或修改
     * @param dataCleanTaskDTO
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public ReturnModel saveOrUpdate(@RequestBody DataCleanTaskDTO dataCleanTaskDTO) {
//        System.out.println(taskDTO);
//        taskDTO.setUserId(UserContext.get());
        DataCleanTask result = dataCleanTaskService.saveOrUpdate(dataCleanTaskDTO);

        return new ReturnModel(200, result, "");
    }

    /**
     * 详情接口
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ResponseBody
    public ReturnModel detail(@RequestParam("id") Integer id) {
        DataCleanTask result = dataCleanTaskService.detail(id);
        return new ReturnModel(200, result, "");
    }

    /**
     * 立即执行
     * @param id
     * @return
     */
    @GetMapping("/actionNow")
    @ResponseBody
    public ReturnModel actionNow(@RequestParam("id") Integer id) {
        dataCleanTaskService.actionNow(id);
        return new ReturnModel(200, null, "");
    }

    /**
     * 删除任务
     * @param id
     * @return
     */
    @GetMapping("/delete")
    @ResponseBody
    public ReturnModel delete(@RequestParam("id") Integer id) {
        dataCleanTaskService.delete(id);
        return new ReturnModel(200, null, "");
    }
}
